#include <stdio.h>
#include <algorithm>
using namespace std;

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))

#define rep(i,n) for (int i=0; i<n; i++)

#define INF 0x3f3f3f3f

int dist[110][110];
int c, s, q;
int test;

int main() {
	test=0;

	while(1) {
		scanf("%d %d %d", &c, &s, &q);

		if (!c && !s && !q) break;

		if (test) printf("\n");
		test++;

		rep(i,c) rep(j,c) dist[i][j]=INF;

		rep(i,s) {
			int a, b, cost;
			scanf("%d %d %d", &a, &b, &cost);
			a--; b--;
			dist[a][b]=dist[b][a]=cost;
		}
		
		rep(k,c) rep(i,c) rep(j,c) {
			dist[i][j]=min(dist[i][j], max(dist[i][k], dist[k][j]));		
		}
	
		TRACE(
			rep(i,c) {
				rep(j,c) printf("%d ", dist[i][j]);
				printf("\n");
			}
		);

		printf("Case #%d\n", test);

		rep(i,q) {
			int a, b;
			scanf("%d %d", &a, &b);
			a--; b--;
			if (dist[a][b]==INF) printf("no path\n");
			else printf("%d\n", dist[a][b]);
		}
	}
	return 0;
}
